﻿using System;
using System.Collections.Generic;
using UnityEngine.UIElements;
using winS.Unity.Process;
using winS.UnityEditor.UIElement;

namespace winS.UnityEditor.ProcessEditor
{
    /// <summary>
    /// 通用步骤节点.
    /// 提供一个输入端口和一个输出端口
    /// </summary>
    public abstract class GeneralStepNode<T> : PortStepNode<T>, IInputable, IOutputable where T : class, IGeneralStep
    {
        public InputPort inputPort { get; protected set; }
        public OutputPort outputPort { get; protected set; }

        internal override void Initialize()
        {
            base.Initialize();

            portContainer.style.justifyContent = Justify.SpaceBetween;

            portContainer.Add(inputPort = new InputPort(this));
            inputPort.style.marginBottom = inputPort.style.marginTop = 8f;

            portContainer.Add(guiFactory.CreateVerticalSplitline(NodeContent.defaultBackgroundColor, 2f));

            portContainer.Add(outputPort = new OutputPort(this, step.nextStepsList));
            outputPort.style.marginBottom = outputPort.style.marginTop = 8f;
        }

        public override Connectionline RequestConnect(OutputPort outputPort)
        {
            return stepGraphView.ConnectPort(inputPort, outputPort);
        }

        IEnumerable<InputPort> IInputable.GetInputPorts()
        {
            yield return inputPort;
        }
        IEnumerable<OutputPort> IOutputable.GetOutputPorts()
        {
            yield return outputPort;
        }
    }
}